Skip to content

Zephyr: Auto-export models from prj.conf#19369

Open
zingo wants to merge 3 commits intopytorch:mainfrom
zingo:Zephyr-Auto-export-models-from-prj.conf
Open

Zephyr: Auto-export models from prj.conf#19369
zingo wants to merge 3 commits intopytorch:mainfrom
zingo:Zephyr-Auto-export-models-from-prj.conf

Conversation

@zingo
Copy link
Copy Markdown
Collaborator

@zingo zingo commented May 7, 2026

Add cmake utility for adding a build rule to run a python file that exports a pytorch model to pte.

Enable using this utility for Zephyr builds and use this in the hello-executorch sample

New config
CONFIG_EXECUTORCH_EXPORT_PYTHON_SCRIPT
to point to your model python file
CONFIG_EXECUTORCH_EXPORT_PYTHON_GENERATED_OUTPUT
to the output file that was generated by the script.
CONFIG_EXECUTORCH_EXPORT_PYTHON_DEPENDENCIES
Make it possible to add dependency files to regenerate the PTE
on next build.

If used this will add cmake rules that will trigger a (re)generation of the PTE if needed when building.

cc @digantdesai @freddan80 @per @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @psiddh @AdrianLundell

Add cmake utility for adding a build rule to run a python file that
exports a pytorch model to pte.

Enable using this utility for Zephyr builds and use this in the
hello-executorch sample

New config
CONFIG_EXECUTORCH_EXPORT_PYTHON_SCRIPT
   to point to your model python file
CONFIG_EXECUTORCH_EXPORT_PYTHON_GENERATED_OUTPUT
   to the output file that was generated by the script.
CONFIG_EXECUTORCH_EXPORT_PYTHON_DEPENDENCIES
   Make it possible to add dependency files to regenerate the PTE
   on next build.

If used thid will add cmake rules that will trigger a (re)generation
of the PTE if needed when building.

Signed-off-by: Zingo Andersen <Zingo.Andersen@arm.com>
Change-Id: Iddebc0316933be3136aefbf28e4fa74e033a76f7
Copilot AI review requested due to automatic review settings May 7, 2026 13:07
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 7, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19369

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 7 Unrelated Failures

As of commit 563b201 with merge base af90130 (image):

NEW FAILURE - The following job has failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 7, 2026
@zingo zingo added the partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm label May 7, 2026
@zingo zingo added module: microcontrollers For embedded MCUs like Cortex-M, or RTOS like Zephyr, does not track NPU backend like Arm Ethos. release notes: arm Changes to the ARM backend delegate labels May 7, 2026
@zingo zingo requested review from psiddh and rascani May 7, 2026 13:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Zephyr-facing CMake/Kconfig plumbing to auto-export ExecuTorch .pte models during configuration, then updates the hello-executorch Zephyr sample to use per-board exporter scripts (Cortex-M / Ethos-U55 / Ethos-U85) and embed the generated model.

Changes:

  • Introduce CONFIG_EXECUTORCH_EXPORT_PYTHON_* Kconfig options and Zephyr CMake helpers to resolve/auto-generate the model and drive selective-op generation.
  • Add reusable CMake utilities for running Python-based model exporters (configure-time and build-time).
  • Update the hello-executorch sample build, docs, and model scripts to use the new auto-export flow (including CI workflow adjustments).

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
zephyr/samples/hello-executorch/src/arm_executor_runner.cpp Adjust logging / output dumping flow and add error-path logging behavior.
zephyr/samples/hello-executorch/sample.yaml Add Zephyr sample metadata/tags.
zephyr/samples/hello-executorch/README.md Document auto-export Kconfig options and updated build/run flows.
zephyr/samples/hello-executorch/prj.conf Configure default exporter script/output for the sample.
zephyr/samples/hello-executorch/models/add.py Remove the older minimal model module format.
zephyr/samples/hello-executorch/models/add_cortex-m.py Add Cortex-M exporter script producing a .pte during configure.
zephyr/samples/hello-executorch/models/add_ethos-u55.py Add Ethos-U55 exporter script producing a .pte during configure.
zephyr/samples/hello-executorch/models/add_ethos-u85.py Add Ethos-U85 exporter script producing a .pte during configure.
zephyr/samples/hello-executorch/CMakeLists.txt Switch sample to new Zephyr model-prepare + header-generation helpers.
zephyr/samples/hello-executorch/boards/mps3_corstone300_fvp.conf Select Ethos-U55 exporter/output for Corstone-300 FVP.
zephyr/samples/hello-executorch/boards/mps4_corstone320_fvp.conf Select Ethos-U85 exporter/output for Corstone-320 FVP.
zephyr/README.md Document Zephyr module usage and new model-export Kconfig settings.
zephyr/Kconfig Add CONFIG_EXECUTORCH_EXPORT_PYTHON_* configuration symbols.
zephyr/ExecuTorchZephyrModel.cmake New: resolve model path, auto-export during configure, and generate model header.
zephyr/CMakeLists.txt Include the new Zephyr model helper CMake module.
tools/cmake/ExportModel.cmake New: generic CMake helpers for running Python exporters at configure/build time.
.gitignore Ignore Zephyr scratch directory.
.github/workflows/trunk.yml Update CI to build/run with auto-export and keep a separate “prebuilt PTE” flow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread zephyr/samples/hello-executorch/src/arm_executor_runner.cpp
Comment thread zephyr/samples/hello-executorch/src/arm_executor_runner.cpp Outdated
Comment thread zephyr/ExecuTorchZephyrModel.cmake
Comment thread zephyr/ExecuTorchZephyrModel.cmake
Comment thread zephyr/ExecuTorchZephyrModel.cmake
Comment thread zephyr/samples/hello-executorch/README.md Outdated
@zingo
Copy link
Copy Markdown
Collaborator Author

zingo commented May 7, 2026

Hi @rascani and @psiddh this add the possibility to autorun lowering in zephyr making the setup quite a bit easier as the aot_arm_compiler does not need to be runned on the side by hand anymore. It also showcase the PythonAPI lowering instead of aot_arm_compiler, we (Arm) has started to think we should nugging people to that and only have aot_arm_compiler script as a convenient addon to be used in some cases as that is more the intended Executorch way and will work on other backends also.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 7, 2026 13:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 3 comments.

Comment thread zephyr/samples/hello-executorch/README.md Outdated
Comment on lines +54 to +59
find_file(
_et_found_export_script
NAMES "${_et_resolved_export_script}"
HINTS "${CMAKE_CURRENT_SOURCE_DIR}" "${_et_zephyr_workspace_dir}"
PATHS ""
)
Comment thread zephyr/Kconfig
Comment on lines +79 to +80
Optional output path that Zephyr expects the exporter script to
write. Relative paths are resolved from the sample build directory.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 8, 2026 05:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.

Comment on lines +52 to +59
if(_et_has_export_script)
set(_et_resolved_export_script "${CONFIG_EXECUTORCH_EXPORT_PYTHON_SCRIPT}")
find_file(
_et_found_export_script
NAMES "${_et_resolved_export_script}"
HINTS "${CMAKE_CURRENT_SOURCE_DIR}" "${_et_zephyr_workspace_dir}"
PATHS ""
)
Comment on lines +256 to +257
--model_file_path=${_et_pte_file_path}
--output_path=${CMAKE_CURRENT_BINARY_DIR}/temp.yaml
@rascani
Copy link
Copy Markdown
Contributor

rascani commented May 8, 2026

Hi @rascani and @psiddh this add the possibility to autorun lowering in zephyr making the setup quite a bit easier as the aot_arm_compiler does not need to be runned on the side by hand anymore. It also showcase the PythonAPI lowering instead of aot_arm_compiler, we (Arm) has started to think we should nugging people to that and only have aot_arm_compiler script as a convenient addon to be used in some cases as that is more the intended Executorch way and will work on other backends also.

I agree with the sentiment that the aot_arm_compiler script is a convenient add-on and the Python API. One thing that stands out though, is that we wind up having to copy and paste the same block of code on every export, with certain ops preserved, the CortexMPassManager, and certain EdgeCompileConfig values. I think it would be good if we started defining ExportRecipes for the various Arm backends. Those are intended to reduce that boilerplate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: microcontrollers For embedded MCUs like Cortex-M, or RTOS like Zephyr, does not track NPU backend like Arm Ethos. partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm release notes: arm Changes to the ARM backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants